package mi.payment.bean.datacollection;

/**
 * Created by KenMa on 2018/1/23.
 */

import mi.payment.MyApplication;
import mi.payment.R;
import mi.payment.db.dao.PayDetail;
import sunmi.payment.L3.L3Handler;

/**
 * 支付实体
 */
public class PayInfo {

    /**
     * 批次号
     */
    private String batchNum;
    /**
     * 流水号
     */
    private String voucherNum;
    /**
     * 原交易流水号
     */
    private String oriVoucherNum;
    /**
     * 终端号
     */
    private String terminalNum;
    /**
     * 交易金额
     */
    private String tradeAmount;
    /**
     * 交易时间
     */
    private String tradeTime;
    /**
     * 发卡行
     */
    private String issuingBank;
    /**
     * 收单行
     */
    private String acquiringBank;
    /**
     * 交易平台：
     * 银行卡/支付宝扫码/微信扫码/口碑扫码/银联钱包扫码
     * 支持的交易平台: 0：银行卡；1：支付宝；2:微信;3:口碑；4:银联钱包
     */
    private String tradePlatform;
    /**
     * 交易类型：
     * 消费/消费撤销/退货/预授权/预授权撤销/预授权完成/预授权完成撤销/结算/签到/签退/交易查询 / 冲正
     * 1:消费 2：消费撤销；3：退货  4.预授权 5.预授权撤销 6.预授权完成 7.预授权完成撤销 8.结算 9.签到 10.签退 11.交易查询 12.冲正
     */
    private int tradeType;
    /**
     * 支付方式：
     * 刷卡/IC/NFC/支付宝主扫/支付宝被扫/微信主扫/微信被扫/口碑主扫/口碑被扫/银联钱包主扫/银联钱包被扫
     * 1：刷卡；2：IC；4：NFC；11:支付宝主扫;12:支付宝被扫；21：微信主扫；22：微信被扫；
     * 31：口碑主扫；32：口碑被扫；41：银联钱包主扫；42：银联钱包被扫
     */
    private int payMethod;

    /**
     * 支付通道：
     * 盛付通、富友、通联
     */
    private String payChannel;

    /**
     * 是否L3调用
     * true:是L3调用；false:不是
     */
    private boolean isCallByL3;

    /**
     * 卡bin
     */
    private String cardBin;

    /**
     * 是否需要密码
     */
    private boolean isNeedPwd;

    /**
     * 交易状态：
     * 银行卡交易状态 00：成功；其他：失败；
     * 扫码交易状态 1：成功；-1：失败 2：支付中
     */
    private String tradeStatus;

    /**
     * 是否已打印
     */
    private boolean isPrint;

    /**
     * 商户号
     */
    private String merchantNum;

    /**
     * 本地交易时间戳
     */
    private long time;

    public PayInfo(PayDetail payDetail) {
        this.batchNum = payDetail.BathNo;
        this.voucherNum = payDetail.voucherNo;
        this.oriVoucherNum = payDetail.originalPOSNum;
        this.terminalNum = payDetail.terminalNo;
        this.tradeAmount = String.valueOf(payDetail.amount);
        this.tradeTime = payDetail.TradeTime;
        this.issuingBank = payDetail.issuingBankCode;
        this.acquiringBank = payDetail.acquiringBankCode;
        this.tradePlatform = TransPlatform.getName(payDetail.transPlatform);
        this.tradeType = payDetail.transactionType;
        if (payDetail.transPlatform == 0) {//银行卡
            this.payMethod = payDetail.cardType;
            if (payDetail.CardNo != null && payDetail.CardNo.length() != 0) {
                this.cardBin = payDetail.CardNo.substring(0, 6);
            }
            this.tradeStatus = payDetail.tradeAnswerCode;
        } else {//二维码类交易
            if (payDetail.transPlatform == 1) {//支付宝
                this.payMethod = Integer.parseInt("1" + payDetail.qrCodeScanModel);
            } else if (payDetail.transPlatform == 2) {//微信
                this.payMethod = Integer.parseInt("2" + payDetail.qrCodeScanModel);
            } else if (payDetail.transPlatform == 3) {//口碑
                this.payMethod = Integer.parseInt("3" + payDetail.qrCodeScanModel);
            } else if (payDetail.transPlatform == 4) {//银联
                this.payMethod = Integer.parseInt("4" + payDetail.qrCodeScanModel);
            } else if (payDetail.transPlatform == 5) {//小米钱包
                this.payMethod = Integer.parseInt("5" + payDetail.qrCodeScanModel);
            }
            this.tradeStatus = String.valueOf(payDetail.QRCodeTransState);
        }
        this.payChannel = MyApplication.getInstance().getResources().getString(R.string.app_name);
        this.isCallByL3 = L3Handler.isL3Process();
        this.isNeedPwd = payDetail.isFreePWD == true ? false : true;
        this.isPrint = payDetail.isPrinted;
        this.merchantNum = payDetail.merchantNo;
        time = payDetail.TerminalDate != null ? payDetail.TerminalDate : 0;
    }

    public String getBatchNum() {
        return batchNum;
    }

    public void setBatchNum(String batchNum) {
        this.batchNum = batchNum;
    }

    public String getVoucherNum() {
        return voucherNum;
    }

    public void setVoucherNum(String voucherNum) {
        this.voucherNum = voucherNum;
    }

    public String getOriVoucherNum() {
        return oriVoucherNum;
    }

    public void setOriVoucherNum(String oriVoucherNum) {
        this.oriVoucherNum = oriVoucherNum;
    }

    public String getTerminalNum() {
        return terminalNum;
    }

    public void setTerminalNum(String terminalNum) {
        this.terminalNum = terminalNum;
    }

    public String getTradeAmount() {
        return tradeAmount;
    }

    public void setTradeAmount(String tradeAmount) {
        this.tradeAmount = tradeAmount;
    }

    public String getTradeTime() {
        return tradeTime;
    }

    public void setTradeTime(String tradeTime) {
        this.tradeTime = tradeTime;
    }

    public String getIssuingBank() {
        return issuingBank;
    }

    public void setIssuingBank(String issuingBank) {
        this.issuingBank = issuingBank;
    }

    public String getAcquiringBank() {
        return acquiringBank;
    }

    public void setAcquiringBank(String acquiringBank) {
        this.acquiringBank = acquiringBank;
    }

    public String getTradePlatform() {
        return tradePlatform;
    }

    public void setTradePlatform(String tradePlatform) {
        this.tradePlatform = tradePlatform;
    }

    public int getTradeType() {
        return tradeType;
    }

    public void setTradeType(int tradeType) {
        this.tradeType = tradeType;
    }

    public int getPayMethod() {
        return payMethod;
    }

    public void setPayMethod(int payMethod) {
        this.payMethod = payMethod;
    }

    public String getPayChannel() {
        return payChannel;
    }

    public void setPayChannel(String payChannel) {
        this.payChannel = payChannel;
    }

    public boolean isCallByL3() {
        return isCallByL3;
    }

    public void setCallByL3(boolean callByL3) {
        isCallByL3 = callByL3;
    }

    public String getCardBin() {
        return cardBin;
    }

    public void setCardBin(String cardBin) {
        this.cardBin = cardBin;
    }

    public boolean isNeedPwd() {
        return isNeedPwd;
    }

    public void setNeedPwd(boolean needPwd) {
        isNeedPwd = needPwd;
    }

    public String getTradeStatus() {
        return tradeStatus;
    }

    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    public boolean isPrint() {
        return isPrint;
    }

    public void setPrint(boolean print) {
        isPrint = print;
    }

    public String getMerchantNum() {
        return merchantNum;
    }

    public void setMerchantNum(String merchantNum) {
        this.merchantNum = merchantNum;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }
}
